<script lang="ts">
import CampaignEdit from './CampaignEdit.vue';

export const addCampaignPopup = useAntdModal(
  // eslint-disable-next-line import/no-self-import
  defineAsyncComponent(() => import('./CampaignEdit.add.vue')),
  {
    title: computed(() => $t('rk5dXlx5tOtx70jLb6U9')),
    wrapClassName: 'ant-cover__Modal-drawer __screen-drawer',
    centered: true,
    footer: null,
  },
);
</script>

<script lang="ts" setup>
const emits = defineEmits<{
  close: [];
}>();

const channelAddMut = useMutation({
  mutationKey: [apis.apiInviteAddChannel.id],
  mutationFn: apis.apiInviteAddChannel.setDefaultConfig({ successMessage: $t('zsaLk1KtXyRrJmdsq5Jo2') }),
});

async function confirm(data: VueEmitParam<typeof CampaignEdit, 'confirm'>) {
  await channelAddMut.mutateAsync({ requestBody: data });
  queryClient.invalidateQueries({ queryKey: [apis.apiInviteChannel.id], exact: false });
  emits('close');
}
</script>

<template>
  <div>
    <CampaignEdit
      :loading="channelAddMut.isPending.value"
      @confirm="confirm"
    />
  </div>
</template>
